import requests,re

# 爬取豆瓣图书首页的: 图书地址 图书名称 图书封面 作者 出版日期
content = requests.get('https://book.douban.com').text

pattern = re.compile('<li.*?cover.*?href="(.*?)".*?title="(.*?)".*?src="(.*?)".*?more-meta.*?<span.*?author">(.*?)</span>.*?year">(.*?)</span>.*?</li>',re.S)

results = re.findall(pattern, content)

# file1 =open("songlist.txt","wb")
#             for key in songdict:
#                 if songdict[key].find('.flv')== -1:
#                     file1.write(key+'-*-'+songdict[key].encode(self.charset)+'\n')
#             file1.close()

file = open("douban100.txt", "wb")
for result in results:
    address, name, cover, author, date = result
    author = re.sub('\s', '', author)
    date = re.sub('\s', '', date)
    data = bytes("图书名称: " +name+ " 图书地址: " +address+ " 封面图片: " +cover+ " 作者: " +author+ " 出版日期: " +date+ "\n", encoding='utf-8')
    file.write(data)
    print(address, name, cover, author, date)
file.close()

